﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Ajax;
using HTMLHelpers.Models;

namespace HTMLHelpers.Controllers
{
    public class FormHelpersController : Controller
    {
        public ActionResult DropDownListWithIEnumerableSample()
        {
            var list = new List<SelectListItem>();
            list.Add(new SelectListItem
            {
                Text = "Professional ASP.NET MVC",
                Value = "1"
            });
            list.Add(new SelectListItem
            {
                Text = "Beginning ASP.NET MVC",
                Value = "2",
                Selected = true
            });
            list.Add(new SelectListItem
            {
                Text = "Professional ASP.NET 3.5",
                Value = "3"
            });
            list.Add(new SelectListItem
            {
                Text = "Professional Visual Studio Extensibility",
                Value = "4"
            });
            ViewData["Books"] = list;
            ViewData["BookList"] = list;
            ViewData["SelectedBook"] = 3;
            return View();
        }

        public ActionResult DropDownListWithSelectListSample()
        {
            var list = new List<Book>();
            list.Add(new Book {
                Id = 1,
                Title = "Professional ASP.NET MVC" 
            });
            list.Add(new Book {
                Id = 2,
                Title = "Beginning ASP.NET MVC"
            });
            list.Add(new Book {
                Id = 3,
                Title = "Professional ASP.NET 3.5"
            });
            list.Add(new Book {
                Id = 4,
                Title = "Professional Visual Studio Extensibility"
            });
            ViewData["Books"] = new SelectList(list, "Id", "Title", 2);
            ViewData["BookList"] = new SelectList(list, "Id", "Title");
            ViewData["SelectedBook"] = 3;
            return View();
        }

        public ActionResult ListBoxSample()
        {
            var list = new List<Book>();
            list.Add(new Book
            {
                Id = 1,
                Title = "Professional ASP.NET MVC"
            });
            list.Add(new Book
            {
                Id = 2,
                Title = "Beginning ASP.NET MVC"
            });
            list.Add(new Book
            {
                Id = 3,
                Title = "Professional ASP.NET 3.5"
            });
            list.Add(new Book
            {
                Id = 4,
                Title = "Professional Visual Studio Extensibility"
            });
            ViewData["Books"] = new MultiSelectList(list, "Id", "Title", new []{1,2});
            ViewData["BookList"] = new MultiSelectList(list, "Id", "Title");
            ViewData["SelectedBook"] = new []{1,4};
            return View();
        }

        public ActionResult FormSample()
        {
            return View();
        }

        public ActionResult CheckBoxSample()
        {
            ViewData["Visible"] = true;
            return View();
        }

        public ActionResult RadioButtonSample()
        {
            ViewData["Gender"] = "female";
            return View();
        }

        public ActionResult TextBoxSample()
        {
            ViewData["booktitle"] = "Beginning ASP.NET MVC";
            var data = new TransferObject
                {
                    Book = new Book
                    {
                        Title = "Beginning ASP.NET MVC",
                        Publisher = "Wrox"
                    }
                };
            return View(data);
        }

        public ActionResult TextAreaSample()
        {
            ViewData["booktitle"] = "Beginning ASP.NET MVC";
            var data = new TransferObject
            {
                Book = new Book
                {
                    Title = "Beginning ASP.NET MVC",
                    Publisher = "Wrox",
                    Summary = "Lorem ipsum..."
                }
            };
            return View(data);
        }
    }

    public class TransferObject
    {
        public Book Book { get; set; }
    }
}
